package middleware

import (
	"github.com/gin-gonic/gin"
	"net/http"
	 "yak.admin/src/entity"
	"yak.admin/src/util"
)

func AuthRequired() gin.HandlerFunc {
	return func(c *gin.Context) {
		if admin, ok := util.GetSession(c, util.SessionAdminKey).(entity.Admin); ok {
			c.Set(util.AdminKey, admin)
			c.Next()
			return
		}
		c.Redirect(http.StatusFound, "/login")
		c.Abort()
	}
}
